const { defineConfig } = require('@vue/cli-service')

const path = require('path')
const resolve = (dir) => {
  return path.join(__dirname, dir)
}

const port = process.env.VUE_APP_PORT
const CompressionPlugin = require('compression-webpack-plugin')

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    port: port,
    host: '0.0.0.0',
    https: false,
    open: true,
    proxy: {
      '/api': {
        // 要代理的地址
        target: 'http://localhost:8088',
        // 配置了这个可以从 http 代理到 https
        // 依赖 origin 的功能可能需要这个，比如 cookie
        changeOrigin: true,
      },
    },
  },
  // 配置别名
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src')) // key,value自行定义，比如.set('@@', resolve('src/components'))
      .set('_c', resolve('src/components'))
  },
  //关闭eslint
  lintOnSave: false,
  // 打包时不生成.map文件 避免看到源码
  productionSourceMap: false,
  // Webpack的进一步配置,压缩指定文件
  configureWebpack: {
    plugins: [
      new CompressionPlugin({
        test: /\.js$|\.html$|\.css/,
        threshold: 10240,
      }),
    ],
  },
})
